package loganalyzervma;

//Imports
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author eladh, alaa, ashenhav
 */
public class LogAnalyzerVmaUI extends javax.swing.JFrame implements Runnable{
    private String version = "1.0.1.4";
    private Component aComponent;
    private final JFileChooser fileChooser = new JFileChooser();
    private BufferedReader bufferedReader;
    private Thread thread;
    private CardObject cardsHolder = new CardObject();
    private ArrayList foundInterfaces = new ArrayList();
    private Interfacedetail interfaceHolder = new Interfacedetail();
    private String defaultSavePath = new String();
    DefaultTableModel generalModel;
    DefaultTableModel parametersModel;
    DefaultTableModel errorsModel;
    DefaultTableModel routeModel;
    DefaultTableModel intefacesModel;
    DefaultTableModel cardsModel;
    DefaultTableModel rulesModel;
    DefaultTableModel interfacedetailModel;
    DefaultTableModel freeSearchModel;
    
    /**
     * Creates new form LogAnalyzerVmaUI
     */
    public LogAnalyzerVmaUI() {
        initComponents();
        setDefaultSavePath();
        generalModel = (DefaultTableModel) generalTable.getModel();
        parametersModel = (DefaultTableModel) parametersTable.getModel();
        errorsModel = (DefaultTableModel) errorsTable.getModel();
        routeModel = (DefaultTableModel) routeTable.getModel();
        cardsModel = (DefaultTableModel) cardsTable.getModel();
        rulesModel = (DefaultTableModel) rulesTable.getModel();
        interfacedetailModel = (DefaultTableModel) interfacedetailTable.getModel();
        freeSearchModel = (DefaultTableModel) freeSearchTable.getModel();
        clearAllFields(true);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFileChooser1 = new javax.swing.JFileChooser();
        Panel = new javax.swing.JTabbedPane();
        startPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jProgressBar = new javax.swing.JProgressBar();
        pleaseWaitMsgLabel = new javax.swing.JLabel();
        Button = new javax.swing.JButton();
        mellanoxSupportjLabel = new javax.swing.JLabel();
        generalPanel = new javax.swing.JPanel();
        jScrollPaneGeneral = new javax.swing.JScrollPane();
        generalTable = new javax.swing.JTable();
        cardsPanel = new javax.swing.JPanel();
        jScrollPaneCards = new javax.swing.JScrollPane();
        cardsTable = new javax.swing.JTable();
        interfacedetailPanel = new javax.swing.JPanel();
        jScrollPaneInterfaceDetail = new javax.swing.JScrollPane();
        interfacedetailTable = new javax.swing.JTable();
        parametersPanel = new javax.swing.JPanel();
        jScrollPaneParameters = new javax.swing.JScrollPane();
        parametersTable = new javax.swing.JTable();
        errorsPanel = new javax.swing.JPanel();
        jScrollPaneErrors = new javax.swing.JScrollPane();
        errorsTable = new javax.swing.JTable();
        routePanel = new javax.swing.JPanel();
        jScrollPaneRoute = new javax.swing.JScrollPane();
        routeTable = new javax.swing.JTable();
        rulesPanel = new javax.swing.JPanel();
        jScrollPaneRules = new javax.swing.JScrollPane();
        rulesTable = new javax.swing.JTable();
        freeSearchPanel = new javax.swing.JPanel();
        keywordjTextField1 = new javax.swing.JTextField();
        keywordjLabel1 = new javax.swing.JLabel();
        keywordjLabel2 = new javax.swing.JLabel();
        keywordjTextField4 = new javax.swing.JTextField();
        keywordjLabel5 = new javax.swing.JLabel();
        keywordjTextField3 = new javax.swing.JTextField();
        keywordjLabel4 = new javax.swing.JLabel();
        keywordjTextField2 = new javax.swing.JTextField();
        keywordjLabel3 = new javax.swing.JLabel();
        keywordjTextField5 = new javax.swing.JTextField();
        keywordjCheckBox1 = new javax.swing.JCheckBox();
        keywordjCheckBox2 = new javax.swing.JCheckBox();
        keywordjCheckBox3 = new javax.swing.JCheckBox();
        keywordjCheckBox4 = new javax.swing.JCheckBox();
        keywordjCheckBox5 = new javax.swing.JCheckBox();
        jScrollPaneFreeSearch = new javax.swing.JScrollPane();
        freeSearchTable = new javax.swing.JTable();
        doneLabel = new javax.swing.JLabel();
        jMenuBar = new javax.swing.JMenuBar();
        jMenuFile = new javax.swing.JMenu();
        jMenuFileOpenLog = new javax.swing.JMenuItem();
        exportToHtmlBtn = new javax.swing.JMenuItem();
        jMenuClear = new javax.swing.JMenuItem();
        jMenuFileExit = new javax.swing.JMenuItem();
        jMenuAbout = new javax.swing.JMenu();
        jMenuAboutVersion = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("VMA Log Analyzer");
        setIconImage(Toolkit.getDefaultToolkit().getImage(LogAnalyzerVmaUI.class.getResource("vma_transparent.png")));
        setIconImages(getIconImages());
        setMinimumSize(new java.awt.Dimension(610, 610));
        setPreferredSize(new java.awt.Dimension(610, 610));
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        startPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/loganalyzervma/Mellanox_logoPNG.png"))); // NOI18N
        jLabel1.setToolTipText("Go to www.mellanox.com");
        jLabel1.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jLabel1MouseClicked(evt);
            }
        });
        startPanel.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(287, 60, -1, -1));
        startPanel.add(jProgressBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(132, 391, 463, 23));

        pleaseWaitMsgLabel.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        pleaseWaitMsgLabel.setText("Analyzing Log....");
        startPanel.add(pleaseWaitMsgLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 360, 100, -1));

        Button.setText("Open Log");
        Button.setToolTipText("Start a new log analyze");
        Button.setMaximumSize(new java.awt.Dimension(87, 25));
        Button.setMinimumSize(new java.awt.Dimension(87, 25));
        Button.setPreferredSize(new java.awt.Dimension(87, 25));
        Button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonActionPerformed(evt);
            }
        });
        startPanel.add(Button, new org.netbeans.lib.awtextra.AbsoluteConstraints(321, 425, -1, 33));

        mellanoxSupportjLabel.setForeground(new java.awt.Color(0, 0, 255));
        mellanoxSupportjLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        mellanoxSupportjLabel.setText("Mellanox Support");
        mellanoxSupportjLabel.setToolTipText("Go to Mellanox Support");
        mellanoxSupportjLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        mellanoxSupportjLabel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                mellanoxSupportjLabelMouseClicked(evt);
            }
        });
        startPanel.add(mellanoxSupportjLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 190, -1, -1));

        Panel.addTab("Start", startPanel);

        generalTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "General Information"
            }
        ));
        jScrollPaneGeneral.setViewportView(generalTable);

        javax.swing.GroupLayout generalPanelLayout = new javax.swing.GroupLayout(generalPanel);
        generalPanel.setLayout(generalPanelLayout);
        generalPanelLayout.setHorizontalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneGeneral, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        generalPanelLayout.setVerticalGroup(
            generalPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(generalPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneGeneral, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("General", generalPanel);

        cardsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "NIC", "Port", "ETH/IB", "State", "Width", "Speed", "FW"
            }
        ));
        jScrollPaneCards.setViewportView(cardsTable);
        cardsTable.getColumnModel().getColumn(5).setHeaderValue("Speed");
        cardsTable.getColumnModel().getColumn(6).setHeaderValue("FW");

        javax.swing.GroupLayout cardsPanelLayout = new javax.swing.GroupLayout(cardsPanel);
        cardsPanel.setLayout(cardsPanelLayout);
        cardsPanelLayout.setHorizontalGroup(
            cardsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cardsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneCards, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        cardsPanelLayout.setVerticalGroup(
            cardsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(cardsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneCards, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Cards", cardsPanel);

        interfacedetailTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name", "IP", "Netmask", "MTU", "HW adress"
            }
        ));
        jScrollPaneInterfaceDetail.setViewportView(interfacedetailTable);

        javax.swing.GroupLayout interfacedetailPanelLayout = new javax.swing.GroupLayout(interfacedetailPanel);
        interfacedetailPanel.setLayout(interfacedetailPanelLayout);
        interfacedetailPanelLayout.setHorizontalGroup(
            interfacedetailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(interfacedetailPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneInterfaceDetail, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        interfacedetailPanelLayout.setVerticalGroup(
            interfacedetailPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(interfacedetailPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneInterfaceDetail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Interface Details", interfacedetailPanel);

        parametersTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Parameter", "Description", "Value"
            }
        ));
        jScrollPaneParameters.setViewportView(parametersTable);

        javax.swing.GroupLayout parametersPanelLayout = new javax.swing.GroupLayout(parametersPanel);
        parametersPanel.setLayout(parametersPanelLayout);
        parametersPanelLayout.setHorizontalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(parametersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneParameters, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        parametersPanelLayout.setVerticalGroup(
            parametersPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(parametersPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneParameters, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Parameters", parametersPanel);

        errorsTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Origin", "Error Description"
            }
        ));
        jScrollPaneErrors.setViewportView(errorsTable);
        errorsTable.getColumnModel().getColumn(0).setMaxWidth(130);

        javax.swing.GroupLayout errorsPanelLayout = new javax.swing.GroupLayout(errorsPanel);
        errorsPanel.setLayout(errorsPanelLayout);
        errorsPanelLayout.setHorizontalGroup(
            errorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(errorsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneErrors, javax.swing.GroupLayout.DEFAULT_SIZE, 704, Short.MAX_VALUE)
                .addGap(14, 14, 14))
        );
        errorsPanelLayout.setVerticalGroup(
            errorsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(errorsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneErrors, javax.swing.GroupLayout.PREFERRED_SIZE, 427, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Errors", errorsPanel);

        routeTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Destination", "Netmask", "Interface"
            }
        ));
        jScrollPaneRoute.setViewportView(routeTable);

        javax.swing.GroupLayout routePanelLayout = new javax.swing.GroupLayout(routePanel);
        routePanel.setLayout(routePanelLayout);
        routePanelLayout.setHorizontalGroup(
            routePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(routePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneRoute, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        routePanelLayout.setVerticalGroup(
            routePanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(routePanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneRoute, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Route table", routePanel);

        rulesTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Defined Rules"
            }
        ));
        jScrollPaneRules.setViewportView(rulesTable);

        javax.swing.GroupLayout rulesPanelLayout = new javax.swing.GroupLayout(rulesPanel);
        rulesPanel.setLayout(rulesPanelLayout);
        rulesPanelLayout.setHorizontalGroup(
            rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneRules, javax.swing.GroupLayout.DEFAULT_SIZE, 708, Short.MAX_VALUE)
                .addContainerGap())
        );
        rulesPanelLayout.setVerticalGroup(
            rulesPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rulesPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPaneRules, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(31, Short.MAX_VALUE))
        );

        Panel.addTab("Rules", rulesPanel);

        keywordjTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keywordjTextField1KeyTyped(evt);
            }
        });

        keywordjLabel1.setText("Keyword 1");

        keywordjLabel2.setText("Keyword 2");

        keywordjTextField4.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keywordjTextField4KeyTyped(evt);
            }
        });

        keywordjLabel5.setText("Keyword 5");

        keywordjTextField3.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keywordjTextField3KeyTyped(evt);
            }
        });

        keywordjLabel4.setText("Keyword 4");

        keywordjTextField2.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keywordjTextField2KeyTyped(evt);
            }
        });

        keywordjLabel3.setText("Keyword 3");

        keywordjTextField5.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                keywordjTextField5KeyTyped(evt);
            }
        });

        keywordjCheckBox1.setText("Enabled");

        keywordjCheckBox2.setText("Enabled");

        keywordjCheckBox3.setText("Enabled");

        keywordjCheckBox4.setText("Enabled");

        keywordjCheckBox5.setText("Enabled");

        freeSearchTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Free Search"
            }
        ));
        jScrollPaneFreeSearch.setViewportView(freeSearchTable);

        javax.swing.GroupLayout freeSearchPanelLayout = new javax.swing.GroupLayout(freeSearchPanel);
        freeSearchPanel.setLayout(freeSearchPanelLayout);
        freeSearchPanelLayout.setHorizontalGroup(
            freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(freeSearchPanelLayout.createSequentialGroup()
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(freeSearchPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(freeSearchPanelLayout.createSequentialGroup()
                                .addComponent(keywordjLabel5)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(keywordjTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(freeSearchPanelLayout.createSequentialGroup()
                                .addComponent(keywordjLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(keywordjTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, freeSearchPanelLayout.createSequentialGroup()
                                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(keywordjLabel2)
                                    .addComponent(keywordjLabel1)
                                    .addComponent(keywordjLabel3))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(keywordjTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE)
                                    .addComponent(keywordjTextField1)
                                    .addComponent(keywordjTextField2))))
                        .addGap(18, 18, 18)
                        .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(keywordjCheckBox1, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(keywordjCheckBox2, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(keywordjCheckBox3, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(keywordjCheckBox4, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(keywordjCheckBox5, javax.swing.GroupLayout.Alignment.TRAILING)))
                    .addGroup(freeSearchPanelLayout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addComponent(jScrollPaneFreeSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 684, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(24, Short.MAX_VALUE))
        );
        freeSearchPanelLayout.setVerticalGroup(
            freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(freeSearchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(keywordjLabel1)
                    .addComponent(keywordjTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(keywordjCheckBox1))
                .addGap(18, 18, 18)
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(keywordjLabel2)
                    .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(keywordjTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(keywordjCheckBox2)))
                .addGap(18, 18, 18)
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(keywordjLabel3)
                    .addComponent(keywordjCheckBox3)
                    .addComponent(keywordjTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(keywordjLabel4)
                    .addComponent(keywordjCheckBox4)
                    .addComponent(keywordjTextField4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(freeSearchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(keywordjLabel5)
                    .addComponent(keywordjTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(keywordjCheckBox5))
                .addGap(18, 18, 18)
                .addComponent(jScrollPaneFreeSearch, javax.swing.GroupLayout.DEFAULT_SIZE, 243, Short.MAX_VALUE)
                .addContainerGap())
        );

        Panel.addTab("Free Search", freeSearchPanel);

        getContentPane().add(Panel, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 19, -1, -1));

        doneLabel.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        doneLabel.setAlignmentY(0.0F);
        getContentPane().add(doneLabel, new org.netbeans.lib.awtextra.AbsoluteConstraints(302, 560, -1, -1));

        jMenuFile.setText("File");

        jMenuFileOpenLog.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        jMenuFileOpenLog.setText("Open Log");
        jMenuFileOpenLog.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuFileOpenLogActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuFileOpenLog);

        exportToHtmlBtn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_MASK));
        exportToHtmlBtn.setText("Export To HTML");
        exportToHtmlBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exportToHtmlBtnActionPerformed(evt);
            }
        });
        jMenuFile.add(exportToHtmlBtn);

        jMenuClear.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuClear.setText("Clear");
        jMenuClear.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuClearActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuClear);

        jMenuFileExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        jMenuFileExit.setText("Exit");
        jMenuFileExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuFileExitActionPerformed(evt);
            }
        });
        jMenuFile.add(jMenuFileExit);

        jMenuBar.add(jMenuFile);

        jMenuAbout.setText("About");

        jMenuAboutVersion.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V, java.awt.event.InputEvent.CTRL_MASK));
        jMenuAboutVersion.setText("Version");
        jMenuAboutVersion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuAboutVersionActionPerformed(evt);
            }
        });
        jMenuAbout.add(jMenuAboutVersion);

        jMenuBar.add(jMenuAbout);

        setJMenuBar(jMenuBar);

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-769)/2, (screenSize.height-710)/2, 769, 710);
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuFileExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuFileExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_jMenuFileExitActionPerformed

    private void jMenuFileOpenLogActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuFileOpenLogActionPerformed
        clearAllFields(false);
        Button.setText("Stop");
        doneLabel.setText("Operation Completed!");
        if (fileChooser.showOpenDialog(aComponent) != JFileChooser.CANCEL_OPTION){
            if (fileChooser.getSelectedFile() != null) {
                thread = new Thread(this);
                thread.start();
            }
            else {
                Button.setText("Open Log");
            }
        }
        else{
            Button.setText("Open Log");
        }
    }//GEN-LAST:event_jMenuFileOpenLogActionPerformed

    private void jMenuAboutVersionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuAboutVersionActionPerformed
        JFrame versionFrame = new JFrame();
        versionFrame.setIconImage(Toolkit.getDefaultToolkit().getImage(LogAnalyzerVmaUI.class.getResource("vma_transparent.png")));
        setIconImages(getIconImages());
        // Get the size of the screen
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        versionFrame.setSize(450, 250);
        // Determine the new location of the window
        int w = versionFrame.getSize().width;
        int h = versionFrame.getSize().height;
        int x = (dim.width-w)/2;
        int y = (dim.height-h)/2;
        // Move the window
        versionFrame.setLocation(x, y);
        JLabel versionLabel = new JLabel("VMA Log Analyzer - " + version, JLabel.CENTER);
        versionLabel.setToolTipText("support@mellanox.com");
        versionFrame.add(versionLabel);        
	versionFrame.show();
    }//GEN-LAST:event_jMenuAboutVersionActionPerformed

    private void jMenuClearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuClearActionPerformed
        clearAllFields(true);
    }//GEN-LAST:event_jMenuClearActionPerformed

    private void exportToHtmlBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exportToHtmlBtnActionPerformed
        exportToHtmlFile(this.defaultSavePath);
    }//GEN-LAST:event_exportToHtmlBtnActionPerformed

    private void keywordjTextField1KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keywordjTextField1KeyTyped
        keywordjCheckBox1.setSelected(true);
    }//GEN-LAST:event_keywordjTextField1KeyTyped

    private void keywordjTextField2KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keywordjTextField2KeyTyped
        keywordjCheckBox2.setSelected(true);
    }//GEN-LAST:event_keywordjTextField2KeyTyped

    private void keywordjTextField3KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keywordjTextField3KeyTyped
        keywordjCheckBox3.setSelected(true);
    }//GEN-LAST:event_keywordjTextField3KeyTyped

    private void keywordjTextField4KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keywordjTextField4KeyTyped
        keywordjCheckBox4.setSelected(true);
    }//GEN-LAST:event_keywordjTextField4KeyTyped

    private void keywordjTextField5KeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_keywordjTextField5KeyTyped
        keywordjCheckBox5.setSelected(true);
    }//GEN-LAST:event_keywordjTextField5KeyTyped

    private void ButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonActionPerformed
        if (Button.getText().equals("Open Log")) {
            jMenuFileOpenLogActionPerformed(evt);
        }
        else if (Button.getText().equals("Stop")) {
            Button.setText("Open Log");
            doneLabel.setText("Operation Cancelled! ");
            try {
                if (bufferedReader != null) {
                    bufferedReader.close();
                }
            } catch (IOException ex) {
                Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "Operation stopped by user!", "VMA Log Analyzer", JOptionPane.PLAIN_MESSAGE );
            }
            try {
                if (thread != null){
                    thread.interrupt();
                    thread = null;
                }
            } catch (Exception ex) {
                Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
                JOptionPane.showMessageDialog(null, "Operation stopped by user!", "VMA Log Analyzer", JOptionPane.PLAIN_MESSAGE );
            }
        }

    }//GEN-LAST:event_ButtonActionPerformed

    private void jLabel1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jLabel1MouseClicked
        try {
            java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
            java.net.URI uri;
            uri = new java.net.URI("http://www.mellanox.com");
                desktop.browse(uri);
            }
        catch ( Exception e ) {
                System.err.println( e.getMessage() );
            }
    }//GEN-LAST:event_jLabel1MouseClicked

    private void mellanoxSupportjLabelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_mellanoxSupportjLabelMouseClicked
        try {
            java.awt.Desktop desktop = java.awt.Desktop.getDesktop();
            java.net.URI uri;
            uri = new java.net.URI("http://support.mellanox.com");
                desktop.browse(uri);
            }
        catch ( Exception e ) {
                System.err.println( e.getMessage() );
            }
    }//GEN-LAST:event_mellanoxSupportjLabelMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new LogAnalyzerVmaUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Button;
    private javax.swing.JTabbedPane Panel;
    private javax.swing.JPanel cardsPanel;
    private javax.swing.JTable cardsTable;
    private javax.swing.JLabel doneLabel;
    private javax.swing.JPanel errorsPanel;
    private javax.swing.JTable errorsTable;
    private javax.swing.JMenuItem exportToHtmlBtn;
    private javax.swing.JPanel freeSearchPanel;
    private javax.swing.JTable freeSearchTable;
    private javax.swing.JPanel generalPanel;
    private javax.swing.JTable generalTable;
    private javax.swing.JPanel interfacedetailPanel;
    private javax.swing.JTable interfacedetailTable;
    private javax.swing.JFileChooser jFileChooser1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JMenu jMenuAbout;
    private javax.swing.JMenuItem jMenuAboutVersion;
    private javax.swing.JMenuBar jMenuBar;
    private javax.swing.JMenuItem jMenuClear;
    private javax.swing.JMenu jMenuFile;
    private javax.swing.JMenuItem jMenuFileExit;
    private javax.swing.JMenuItem jMenuFileOpenLog;
    private javax.swing.JProgressBar jProgressBar;
    private javax.swing.JScrollPane jScrollPaneCards;
    private javax.swing.JScrollPane jScrollPaneErrors;
    private javax.swing.JScrollPane jScrollPaneFreeSearch;
    private javax.swing.JScrollPane jScrollPaneGeneral;
    private javax.swing.JScrollPane jScrollPaneInterfaceDetail;
    private javax.swing.JScrollPane jScrollPaneParameters;
    private javax.swing.JScrollPane jScrollPaneRoute;
    private javax.swing.JScrollPane jScrollPaneRules;
    private javax.swing.JCheckBox keywordjCheckBox1;
    private javax.swing.JCheckBox keywordjCheckBox2;
    private javax.swing.JCheckBox keywordjCheckBox3;
    private javax.swing.JCheckBox keywordjCheckBox4;
    private javax.swing.JCheckBox keywordjCheckBox5;
    private javax.swing.JLabel keywordjLabel1;
    private javax.swing.JLabel keywordjLabel2;
    private javax.swing.JLabel keywordjLabel3;
    private javax.swing.JLabel keywordjLabel4;
    private javax.swing.JLabel keywordjLabel5;
    private javax.swing.JTextField keywordjTextField1;
    private javax.swing.JTextField keywordjTextField2;
    private javax.swing.JTextField keywordjTextField3;
    private javax.swing.JTextField keywordjTextField4;
    private javax.swing.JTextField keywordjTextField5;
    private javax.swing.JLabel mellanoxSupportjLabel;
    private javax.swing.JPanel parametersPanel;
    private javax.swing.JTable parametersTable;
    private javax.swing.JLabel pleaseWaitMsgLabel;
    private javax.swing.JPanel routePanel;
    private javax.swing.JTable routeTable;
    private javax.swing.JPanel rulesPanel;
    private javax.swing.JTable rulesTable;
    private javax.swing.JPanel startPanel;
    // End of variables declaration//GEN-END:variables

    //Clear retreived text for frash start
    private void clearAllFields(boolean par) {
        hideLabels();
        jProgressBar.setValue(1);
        if (interfacedetailModel.getDataVector().size() > 0){
            interfacedetailModel.getDataVector().removeAllElements();
            interfacedetailTable.removeAll();
        }
        if (parametersModel.getDataVector().size() > 0){
            parametersModel.getDataVector().removeAllElements();
            parametersTable.removeAll();
        }
        if (routeModel.getDataVector().size() > 0){
            routeModel.getDataVector().removeAllElements();
            routeTable.removeAll();
        }
        if (errorsModel.getDataVector().size() > 0){
            errorsModel.getDataVector().removeAllElements();
            errorsTable.removeAll();
        }
        if (generalModel.getDataVector().size() > 0){
            generalModel.getDataVector().removeAllElements();
            generalTable.removeAll();
        }
        if (cardsModel.getDataVector().size() > 0){
            cardsModel.getDataVector().removeAllElements();
            cardsTable.removeAll();
        }
        if (rulesModel.getDataVector().size() > 0){
            rulesModel.getDataVector().removeAllElements();
            rulesTable.removeAll();
        }
        if (freeSearchModel.getDataVector().size() > 0){
            freeSearchModel.getDataVector().removeAllElements();
            freeSearchTable.removeAll();
        }
        if (par) {
            keywordjCheckBox1.setSelected(false);
            keywordjCheckBox2.setSelected(false);
            keywordjCheckBox3.setSelected(false);
            keywordjCheckBox4.setSelected(false);
            keywordjCheckBox5.setSelected(false);
            keywordjTextField1.setText("");
            keywordjTextField2.setText("");
            keywordjTextField3.setText("");
            keywordjTextField4.setText("");
            keywordjTextField5.setText("");
        }
        
    }

    //Hide labels when application is initializing
    private void hideLabels() {
        hideWaitPanel();
        doneLabel.setVisible(false);
    }

    @Override
    public void run() {
        //Take care of checkboxes which are selected and textbox is empty
        takeCareCheckBoxes();        
        boolean runFlag = true;
        showWaitPanel();
        
        try {
            bufferedReader = new BufferedReader(new FileReader(fileChooser.getSelectedFile()));
        }
        catch (IOException ex) {
            Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        String currentLine;
        try {
            // variables for the progress bar
            double progress = 1;
            double len = (int)new File(fileChooser.getSelectedFile().getPath()).length();
            // get a line
            while (runFlag && (currentLine = bufferedReader.readLine())!=null){
                // get general information
                if (currentLine.contains(": Version:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("VMA Version: " + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    // add the row to the table
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains("Revision")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("VMA Revision: " + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains("OFED Version:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("OFED Version:" + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains(": System:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("Kernel Version:" + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains(": Architecture:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("Architecture version:" + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains(": Node:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("Node: " + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }
                if (currentLine.contains(":  License Directory")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("License Directory: " + currentLine.substring(currentLine.indexOf(":  License Directory ")+1, currentLine.indexOf("[")) + "\n");
                    generalModel.addRow(generalNewRow);
                }
               if (currentLine.contains(": Cmd Line:")) {
                    Vector generalNewRow = new Vector();
                    generalNewRow.add("Cmd Line: " + currentLine.substring(currentLine.lastIndexOf(": ")+1) + "\n");
                    generalModel.addRow(generalNewRow);
                }

                // get cards' details        
                if (currentLine.contains("set_dev_configuration() Setting configuration for the MLX card ")) {
                    cardsHolder.setCardName(currentLine);
                }
                //setFW
                if (currentLine.contains("FW Ver:")) {
                    cardsHolder.setFW(currentLine);
                }
              
                //setPort
                if (currentLine.contains("port_mgr() Port")) {
                    //set Port number
                    cardsHolder.setPort(currentLine);
                    //setCardProfile
                    cardsHolder.setCardProfile(currentLine);
                    //setState
                    cardsHolder.setState(currentLine);
                    //setWidth
                    cardsHolder.setWidth(currentLine);
                    //setSpeed
                    cardsHolder.setSpeed(currentLine);
                
                
                    // add it to the table
                    cardsModel.addRow(cardsHolder.getCardParamContainer());
                    cardsHolder.resetSpeedWidth();
                }
                
                if (currentLine.contains("ib_ctx_handler()")) {
                    Vector cardVMA63NewRow = new Vector();
                    cardVMA63NewRow.add(currentLine.substring(currentLine.indexOf("'") + 1, currentLine.indexOf("' [")));
                    cardVMA63NewRow.add("Not supported");
                    cardVMA63NewRow.add("Not supported");
                    cardVMA63NewRow.add("Not supported");
                    cardVMA63NewRow.add("Not supported");
                    cardVMA63NewRow.add("Not supported");
                    cardVMA63NewRow.add(currentLine.substring(currentLine.indexOf("FW Ver:") + 7));
                    cardsModel.addRow(cardVMA63NewRow);

                }


                // get interface details        
                // setInterfaceNames
                if (currentLine.contains("save_netdev_info() name " )) {
                    interfaceHolder.setinterfaceName(currentLine);
                }
                
                //setip
                if (currentLine.contains("save_netdev_info() ip:")) {
                    interfaceHolder.setip(currentLine);
                }
                //setnetmask
                if (currentLine.contains("save_netdev_info() netmask")) {
                    //set Port number
                    interfaceHolder.setnetmask(currentLine);
                }

                //setmtu
                if (currentLine.contains("save_netdev_info() mtu:")) {
                    //set Port number
                    interfaceHolder.setmtu(currentLine);
                }
                 //setHWadress
                if (currentLine.contains("save_netdev_info() HW adress:")) {
                    interfaceHolder.setHWadress(currentLine);
                    interfacedetailModel.addRow(interfaceHolder.getinterfaceParamContainer());
                }

                 if (currentLine.contains("find_route_val() found route val")) {
                    Vector interfaceVMA63NewRow = new Vector();
                    interfaceVMA63NewRow.add(currentLine.substring(currentLine.indexOf("dev:") + 4, currentLine.indexOf("src:")));
                    interfaceVMA63NewRow.add(currentLine.substring(currentLine.indexOf("src:") + 4, currentLine.indexOf("scope")));
                    interfaceVMA63NewRow.add(currentLine.substring(currentLine.indexOf("netmask:") + 8, currentLine.indexOf("dev:")));
                    interfaceVMA63NewRow.add("Not supported");
                    interfaceVMA63NewRow.add("Not supported");
                    interfacedetailModel.addRow(interfaceVMA63NewRow);

                }




                // get errors
                if (currentLine.contains("Error") || currentLine.contains("errno") || currentLine.contains("ERROR") || currentLine.contains("fail")) {
                    Vector errorsNewRow = new Vector();
                    errorsNewRow.add(currentLine.substring(0, currentLine.indexOf(":")));
                    errorsNewRow.add(currentLine.substring(currentLine.indexOf(":")+1));
                    errorsModel.addRow(errorsNewRow);
                }

                // get Route table
                if (currentLine.contains("dest:")) {
                    Vector routeTableNewRow = new Vector();

                    if (currentLine.contains("src:")){
                        if (currentLine.contains("netmask:")){
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dest:")+5, currentLine.indexOf("netmask: "))); // destination 
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("netmask:")+8, currentLine.indexOf("dev: "))); // netmask
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("src: "))); // interface
                        }
                        else {
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dest:")+5, currentLine.indexOf("gw: "))); // destination 
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("gw:")+8, currentLine.indexOf("dev: "))); // netmask
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("src: "))); // interface
                        }
                    }
                    else{
                        if (currentLine.contains("netmask:")){
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dest:")+5, currentLine.indexOf("netmask: "))); // destination 
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("netmask:")+8, currentLine.indexOf("dev: "))); // netmask
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("scope "))); // interface
                        }
                        else{
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dest:")+5, currentLine.indexOf("gw: "))); // destination 
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("gw:")+8, currentLine.indexOf("dev: "))); // netmask
                            routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("scope "))); // interface
                        }

                    }
                    // add the row to the table
                    if (!routeTableNewRow.isEmpty()) {
                        routeModel.addRow(routeTableNewRow);
                    }
                }
//<<<<<<< .mine
                // route table for IB logs
//=======

//>>>>>>> .r63
                else {
                    if (currentLine.contains("dst:")) {
                        Vector routeTableNewRow = new Vector();

                        if (currentLine.contains("src:")){
                            if (currentLine.contains("netmask:")){
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dst:")+5, currentLine.indexOf("netmask: "))); // destination 
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("netmask:")+8, currentLine.indexOf("dev: "))); // netmask
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("src: "))); // interface
                            }
                            else if (currentLine.contains("gw: ")){
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dst:")+5, currentLine.indexOf("gw: "))); // destination 
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("gw:")+8, currentLine.indexOf("dev: "))); // netmask
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("src: "))); // interface
                            }
                        }
                        else if (currentLine.contains("gw: ")){
                            if (currentLine.contains("netmask:")){
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dst:")+5, currentLine.indexOf("netmask: "))); // destination 
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("netmask:")+8, currentLine.indexOf("dev: "))); // netmask
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("scope "))); // interface
                            }
                            else {
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dst:")+5, currentLine.indexOf("gw: "))); // destination 
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("gw:")+8, currentLine.indexOf("dev: "))); // netmask
                                routeTableNewRow.add(currentLine.substring(currentLine.indexOf("dev:")+4, currentLine.indexOf("scope "))); // interface
                            }

                        }
                        // add the row to the table
                        if (!routeTableNewRow.isEmpty()) {
                            routeModel.addRow(routeTableNewRow);
                        }
                    }
                }

        
                             
                
                
        /*        // get interfaces
                if (currentLine.contains("matching device found for ip")) {
                    String interfaceName = currentLine.substring(currentLine.indexOf("' on")+6, currentLine.indexOf("' (")); // interface;
                    if (!foundInterfaces.contains(interfaceName)){
                        foundInterfaces.add(interfaceName);
                        Vector parametersNewRow = new Vector();
                        parametersNewRow.add(interfaceName); // interface
                        parametersNewRow.add(currentLine.substring(currentLine.indexOf("ip '")+4, currentLine.indexOf("' on"))); // IP
                        // add the row to the table
                       intefacesModel.addRow(parametersNewRow);
                    }
                }  */

                // get parameters
                if (currentLine.contains("VMA_") && currentLine.contains(" [") && currentLine.contains("]")) {
                    Vector parametersNewRow = new Vector();
                    parametersNewRow.add(currentLine.substring(currentLine.indexOf(" [") + 2, currentLine.indexOf("]"))); // parameter
                    String desc = currentLine.substring(currentLine.indexOf(" : ") + 3, currentLine.indexOf("    "));
                    desc = desc.replaceAll("  ", "");
                    parametersNewRow.add(desc); // description
                    String value =  currentLine.substring(currentLine.indexOf(desc) + desc.length(), currentLine.indexOf(" ["));
                    value = value.replaceAll(" ", "");
                    parametersNewRow.add(value); // value   
                    parametersModel.addRow(parametersNewRow); 
                }
                if (currentLine.contains("print_rule()")) {
                    Vector rulesNewRow = new Vector();
                    rulesNewRow.add(currentLine.substring(currentLine.indexOf("print_rule()") + 13));
                    rulesModel.addRow(rulesNewRow);
                }
                
                //Get Free Search
                if (keywordjCheckBox1.isSelected() && !keywordjTextField1.getText().isEmpty() && currentLine.contains(keywordjTextField1.getText())) {
                    Vector freeSearchNewRow = new Vector();
                    freeSearchNewRow.add(currentLine);
                    freeSearchModel.addRow(freeSearchNewRow);
                }
                if (keywordjCheckBox2.isSelected() && !keywordjTextField2.getText().isEmpty() && currentLine.contains(keywordjTextField2.getText())) {
                    Vector freeSearchNewRow = new Vector();
                    freeSearchNewRow.add(currentLine);
                    freeSearchModel.addRow(freeSearchNewRow);
                }
                if (keywordjCheckBox3.isSelected() && !keywordjTextField3.getText().isEmpty() && currentLine.contains(keywordjTextField3.getText())) {
                    Vector freeSearchNewRow = new Vector();
                    freeSearchNewRow.add(currentLine);
                    freeSearchModel.addRow(freeSearchNewRow);
                }
                if (keywordjCheckBox4.isSelected() && !keywordjTextField4.getText().isEmpty() && currentLine.contains(keywordjTextField4.getText())) {
                    Vector freeSearchNewRow = new Vector();
                    freeSearchNewRow.add(currentLine);
                    freeSearchModel.addRow(freeSearchNewRow);
                }
                if (keywordjCheckBox5.isSelected() && !keywordjTextField5.getText().isEmpty() && currentLine.contains(keywordjTextField5.getText())) {
                    Vector freeSearchNewRow = new Vector();
                    freeSearchNewRow.add(currentLine);
                    freeSearchModel.addRow(freeSearchNewRow);
                }
                
                
                
                // update the progress bar
                progress += currentLine.length();
                jProgressBar.setValue((int)Math.round((progress/len)*100));
            } // end of while((currentLine=bufferedReader.readLine())!=null)
            
        }
        catch (Exception ex) {
            try {
                bufferedReader.close();
            } catch (IOException ex1) {
                Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex1);
            }
            Logger.getLogger(LogAnalyzerVmaUI.class.getName()).log(Level.SEVERE, null, ex);
            runFlag = false;
        }
        hideWaitPanel();
    }
    
       
    public void showWaitPanel() {
        pleaseWaitMsgLabel.setVisible(true);
        jProgressBar.setVisible(true);  
        doneLabel.setVisible(false);
    }
    
    private void hideWaitPanel() {
        pleaseWaitMsgLabel.setVisible(false);
        jProgressBar.setIndeterminate(false);
        jProgressBar.setVisible(false);
        Button.setText("Open Log");
        doneLabel.setVisible(true);
    }
    
    private String jtableToHtml(JTable table){
        String html;
        DefaultTableModel dtm = (DefaultTableModel) table.getModel();
        int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount();
        html = "<table border=\"1\">";
        // add the header of the table. ?
        for (int i=0 ; i < nCol ; i++){
            html += "<th>" + dtm.getColumnName(i) + "</th>";
        }
        
        // add the content of the table.
        for (int i = 0 ; i < nRow ; i++)
        {
            html += "<tr>";
            for (int j = 0 ; j < nCol ; j++){
                html += "<td>" + (String)dtm.getValueAt(i,j) + "</td>";
            }
            html += "</tr>";
        }
        html += "</table>";
        return html;
    }
    
    private void exportToHtmlFile(String htmlPath){
        // build the html file 
        String htmlContent = "<html>"
                + "<head>"
                + "<body>"
                + "<pre>";
        htmlContent += "<a name=\"index\"></a>";
        htmlContent += "<h1>VMA Log Analyzer</h1>";
        htmlContent += "<h3>Version " + version + "</h3>";
        
        // index table
        htmlContent += "<a href=\"#general\">General</a>  |   ";
        htmlContent += "<a href=\"#cards\">Cards</a>  |   ";
        htmlContent += "<a href=\"#parameters\">Parameters</a>  |   ";
        htmlContent += "<a href=\"#routeTable\">Route table</a>  |   ";
        htmlContent += "<a href=\"#interfaceDetails\">Interface details</a>  |   ";
        htmlContent += "<a href=\"#rules\">Rules</a>  |   ";
        htmlContent += "<a href=\"#freeSearchTable\">Free Search</a>  |   ";
        htmlContent += "<a href=\"#errors\">Errors</a>";
        
        htmlContent += "<br/>";
        htmlContent += "<div>";
        htmlContent += "<a name=\"general\"></a>";
        htmlContent += "<a href=\"#cards\">next</a>";
        htmlContent += "<h2>General<h2>";
        htmlContent += jtableToHtml(generalTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"cards\"></a>";
        htmlContent += "<a href=\"#general\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#parameters\">next</a>";
        htmlContent += "<h2>Cards<h2>";
        htmlContent += jtableToHtml(cardsTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"parameters\"></a>";
        htmlContent += "<a href=\"#cards\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#routeTable\">next</a>";
        htmlContent += "<h2>Parameters<h2>";
        htmlContent += jtableToHtml(parametersTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"routeTable\"></a>";
        htmlContent += "<a href=\"#parameters\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#interfaceDetails\">next</a>";
        htmlContent += "<h2>Route table<h2>";
        htmlContent += jtableToHtml(routeTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"interfaceDetails\"></a>";
        htmlContent += "<a href=\"#routeTable\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#rules\">next</a>";
        htmlContent += "<h2>Interface details<h2>";
        htmlContent += jtableToHtml(interfacedetailTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"rules\"></a>";
        htmlContent += "<a href=\"#interfaceDetails\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#freeSearchTable\">next</a>";
        htmlContent += "<h2>Rules<h2>";
        htmlContent += jtableToHtml(rulesTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"freeSearchTable\"></a>";
        htmlContent += "<a href=\"#rules\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>  |  ";
        htmlContent += "<a href=\"#errors\">next</a>";
        htmlContent += "<h2>Free Search<h2>";
        htmlContent += jtableToHtml(freeSearchTable);
        htmlContent += "</div>";
        
        htmlContent += "<div>";
        htmlContent += "<a name=\"errors\"></a>";
        htmlContent += "<a href=\"#freeSearchTable\">prev</a>  |  ";
        htmlContent += "<a href=\"#index\">index</a>";
        htmlContent += "<h2>Errors<h2>";
        htmlContent += jtableToHtml(errorsTable);
        htmlContent += "</div>";
        //
        htmlContent += "</pre>"
                + "</body>"
                + "</head>"
                + "</html>";
        // save the html content to a file
        try{
            // Create file 
            JFileChooser jFileChooser = new JFileChooser();
            jFileChooser.setSelectedFile(new File(this.defaultSavePath));
            // get the file path and check if cancel button was clicked
            if (jFileChooser.showSaveDialog(aComponent) != JFileChooser.CANCEL_OPTION){ 
                htmlPath = jFileChooser.getSelectedFile().toString();
                FileWriter fstream = new FileWriter(htmlPath);
                BufferedWriter out = new BufferedWriter(fstream);
                out.write(htmlContent);
                //Close the output stream
                out.close();
                JOptionPane.showMessageDialog(null, htmlPath + " file was created", "VMA Log Analyzer", JOptionPane.PLAIN_MESSAGE );
            }
            
        } catch (Exception e) {//Catch exception if any
            JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), "VMA Log Analyzer - Error", JOptionPane.ERROR_MESSAGE );
            System.err.println("Error: " + e.getMessage());
        }
        
    }

    private void setDefaultSavePath() {
        if ((System.getProperty("os.name").toLowerCase().contains("windows"))) {
            this.defaultSavePath = "C:\\Temp\\" + "VMA_Log_Analyze_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + ".html";
        }
        else {
            this.defaultSavePath = "/tmp/"  + "VMA_Log_Analyze_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + ".html";
        }
    }

    private void takeCareCheckBoxes() {
        if (keywordjCheckBox1.isSelected() && keywordjTextField1.getText().isEmpty()) {
            keywordjCheckBox1.setSelected(false);
        }
        if (keywordjCheckBox2.isSelected() && keywordjTextField2.getText().isEmpty()) {
            keywordjCheckBox2.setSelected(false);
        }
        if (keywordjCheckBox3.isSelected() && keywordjTextField3.getText().isEmpty()) {
            keywordjCheckBox3.setSelected(false);
        }
        if (keywordjCheckBox4.isSelected() && keywordjTextField4.getText().isEmpty()) {
            keywordjCheckBox4.setSelected(false);
        }
        if (keywordjCheckBox5.isSelected() && keywordjTextField5.getText().isEmpty()) {
            keywordjCheckBox5.setSelected(false);
        }
    }

}
